home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / bbs / pprd199.zip / TCP.H < prev    next >
C/C++ Source or Header  |  1994-05-28  |  9KB  |  300 lines

  1.  
  2. /*
  3.  * Waterloo TCP
  4.  *
  5.  * Copyright (c) 1990, 1991, 1992, 1993 Erick Engelke
  6.  *
  7.  * Portions copyright others, see copyright.h for details.
  8.  *
  9.  * This library is free software; you can use it or redistribute under
  10.  * the terms of the license included in LICENSE.H.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * file LICENSE.H for more details.
  16.  *
  17.  */
  18. #ifndef _wattcp_tcp_h
  19. #define _wattcp_tcp_h
  20.  
  21. #ifndef WTCP_VER
  22.  
  23. /* handle some early dumb naming conventions */
  24. #define dbuginit()      dbug_init()
  25.  
  26. /* Kernal version (major major minor minor) */
  27. #define WTCP_VER 0x0102
  28.  
  29. /*
  30.  * Typedefs and constants
  31.  */
  32.  
  33. #ifndef byte
  34. typedef unsigned char byte;
  35. #endif  byte
  36. #ifndef word
  37. typedef unsigned int word;
  38. #endif  word
  39. #ifndef longword
  40. typedef unsigned long longword;
  41. #endif  longword
  42.  
  43. typedef struct {
  44.     byte undoc[ 4300 ];
  45. } tcp_Socket;
  46.  
  47. typedef struct {
  48.     byte undoc[ 2200 ];
  49. } udp_Socket;
  50.  
  51.  
  52. typedef struct sockaddr {
  53.     word        s_type;
  54.     word        s_port;
  55.     longword    s_ip;
  56.     byte        s_spares[6];    /* unused in TCP realm */
  57. };
  58.  
  59. #define sockaddr_in sockaddr
  60.  
  61. typedef struct in_addr {
  62.     longword    s_addr;
  63. };
  64.  
  65.  
  66. #define MAX_COOKIES     10
  67. #define MAX_NAMESERVERS 10
  68.  
  69. #define TCP_MODE_BINARY 0
  70. #define TCP_MODE_ASCII    1
  71. #define UDP_MODE_CHK    0    /*default to checksum */
  72. #define UDP_MODE_NOCHK    2
  73. #define TCP_MODE_NAGLE  0       /* Nagle algorithm */
  74. #define TCP_MODE_NONAGLE 4
  75.  
  76. extern sock_init();
  77. /*
  78.  *   s is the pointer to a udp or tcp socket
  79.  */
  80. extern sock_read(void  *s, byte *dp, int len );
  81. extern sock_fastread(void  *s, byte *dp, int len );
  82. extern sock_write(void  *s, byte *dp, int len);
  83. extern void sock_enqueue(void  *s, byte *dp, int len);
  84. extern sock_fastwrite(void *s, byte *dp, int len );
  85. extern sock_flush( void  *s );
  86. extern sock_flushnext( void  *s);
  87. extern sock_puts( void  *s, byte *dp );
  88. extern word sock_gets( void  *s, byte *dp, int n );
  89. extern byte sock_putc( void  *s, byte c );
  90. extern byte sock_getc( void  *s );
  91. extern word sock_dataready( void  *s );
  92. extern sock_close( void *s );
  93. extern sock_abort( void *s );
  94. extern sock_printf( void  *s, char *format, ... );
  95. extern sock_scanf( void  *s, char *format, ... );
  96. extern sock_mode( void *s, word mode );        /* see TCP_MODE_... */
  97. extern void db_write( char *msg );
  98. extern void dbug_init();
  99. extern void dbug_printf(char *,... );
  100.  
  101. /*
  102.  * TCP or UDP specific stuff, must be used for open's and listens, but
  103.  * sock stuff is used for everything else
  104.  */
  105. extern int udp_open(void *s, word lport, longword ina, word port, int (*datahandler)());
  106. extern int tcp_open(void *s, word lport, longword ina, word port, int (*datahandler)());
  107. extern tcp_listen(void *s, word lport, longword ina, word port, int (*datahandler)(), word timeout);
  108. extern int tcp_established(void *s);
  109. extern char *rip( char *s );
  110. extern longword resolve( char *name);
  111. extern int reverse_addr_lookup(longword ipaddr, char *name);
  112. /*
  113.  * less general functions
  114.  */
  115. extern longword aton( char *text );
  116. extern int isaddr( char *text );
  117. extern tcp_cbreak( word mode );
  118. extern longword intel( longword x );
  119. extern word intel16( word x );
  120.  
  121. /*
  122.  * timers
  123.  */
  124.  
  125. extern void ip_timer_init( void *s , word delayseconds );
  126. extern word ip_timer_expired( void *s );
  127.         /*
  128.          * TCP/IP system variables - do not change these since they
  129.          *      are not necessarily the source variables, instead use
  130.          *      ip_Init function
  131.          */
  132. extern longword my_ip_addr;
  133. extern longword sin_mask;       /* eg.  0xfffffe00L */
  134. extern word sock_delay;
  135.  
  136.         /*
  137.          * tcp_init/tcp_shutdown
  138.          *      - init/kill all tcp and lower services
  139.          *      - only call if you do not use sock_init
  140.          * (NOT RECOMMENDED)
  141.          */
  142. extern tcp_shutdown();
  143. extern tcp_Init();
  144.  
  145. /*
  146.  * things you probably won't need to know about
  147.  */
  148.     /*
  149.      * sock_debugdump
  150.      *    - dump some socket control block parameters
  151.      * used for testing the kernal, not recommended
  152.      */
  153. extern sock_debugdump( void *s);
  154.         /*
  155.          * tcp_config - read a configuration file
  156.          *            - if special path desired, call after sock_init()
  157.          *            - null reads path from executable
  158.          * see sock_init();
  159.          */
  160. extern tcp_config( char *path );
  161.         /*
  162.          * tcp_tick - called periodically by user application in sock_wait_...
  163.          *          - returns 1 when our socket closes
  164.          */
  165. extern tcp_tick( void *s );
  166.         /*
  167.          * Retransmitter - called periodically to perform tcp retransmissions
  168.          *          - normally called from tcp_tick, you have to be pretty
  169.          *            low down to use this one
  170.          */
  171. extern tcp_Retransmitter();
  172.         /*
  173.          * tcp_set_debug_state - set 1 or reset 0 - depends on what I have done
  174.          */
  175. extern tcp_set_debug_state( word x );
  176.  
  177.  
  178. extern int _last_cookie;
  179. extern longword _cookie[MAX_COOKIES];
  180.  
  181.         /*
  182.          * name domain constants
  183.          */
  184.  
  185. extern char *def_domain;
  186. extern longword def_nameservers[ MAX_NAMESERVERS ];
  187.  
  188.  
  189. extern word wathndlcbrk;
  190. extern word watcbroke;
  191. /*
  192.  * sock_wait_... macros
  193.  */
  194. /*
  195.  * sock_wait_established()
  196.  *    - waits then aborts if timeout on s connection
  197.  * sock_wait_input()
  198.  *    - waits for received input on s
  199.  *    - may not be valid input for sock_Gets... check returned length
  200.  * sock_tick()
  201.  *    - do tick and jump on abort
  202.  * sock_wait_closed();
  203.  *    - discards all received data
  204.  *
  205.  * jump to sock_err with contents of *statusptr set to
  206.  *     1 on closed
  207.  *    -1 on timeout
  208.  *
  209.  */
  210. extern int _ip_delay0( void *s, int seconds, int (*fn)(), void *statusptr );
  211. extern int _ip_delay1( void *s, int seconds, int (*fn)(), void *statusptr );
  212. extern int _ip_delay2( void *s, int seconds, int (*fn)(), void *statusptr );
  213.  
  214. extern unsigned long set_timeout( unsigned int seconds );
  215. extern unsigned long set_ttimeout( unsigned int ticks );
  216. extern int chk_timeout( unsigned long timeout );
  217.  
  218.  
  219.  
  220. extern int tcp_tick( void *s );
  221.  
  222. #define sock_wait_established( s, seconds, fn, statusptr ) \
  223.     if (_ip_delay0( s, seconds, fn, statusptr )) goto sock_err;
  224. #define sock_wait_input( s, seconds, fn , statusptr ) \
  225.     if (_ip_delay1( s, seconds, fn, statusptr )) goto sock_err;
  226. #define sock_tick( s, statusptr ) \
  227.     if ( !tcp_tick(s)) { if (statusptr) *statusptr = 1 ; goto sock_err; }
  228. #define sock_wait_closed(s, seconds, fn, statusptr )\
  229.     if (_ip_delay2( s, seconds, fn, statusptr )) goto sock_err;
  230.  
  231. /* user initialization file */
  232. extern void (*usr_init)();
  233.  
  234. extern void outs( char far * string );
  235. extern longword aton( char * string);
  236.  
  237. /*
  238.  * Send an icmp echo request using specified ttl and tos.
  239.  * if(icmp_id != NULL) store copy of the id there
  240.  */
  241. extern int _send_ping( longword host, longword countnum, byte ttl,
  242.                                             byte tos, longword *theid );
  243. /* backward compatibility */
  244. #define _ping( h, c ) _send_ping( h, c, 250, 0, NULL )
  245. extern longword _chk_ping( longword host , longword *ptr);
  246. extern void _arp_register( longword use, longword instead_of );
  247.  
  248.  
  249.  
  250. extern void _eth_init();
  251. extern byte *_eth_formatpacket( void *eth_dest, word eth_type );
  252. extern void _eth_send( word len);
  253. extern void _eth_free( void *buf);
  254. extern byte *_eth_arrived( word *type_ptr);
  255. extern void _eth_release();
  256.  
  257.  
  258.  
  259. /* bsd-similar stuff */
  260.  
  261. extern int sock_rbsize( void *s );
  262. extern int sock_rbused( void *s );
  263. extern int sock_rbleft( void *s );
  264. extern int sock_tbsize( void *s );
  265. extern int sock_tbused( void *s );
  266. extern int sock_tbleft( void *s );
  267.  
  268.  
  269. extern _chk_socket( tcp_Socket *s );
  270. extern char *inet_ntoa( char *s, longword x );
  271. extern char *psocket( tcp_Socket *s );
  272. extern longword inet_addr( char *s );
  273. extern char *sockerr( tcp_Socket *s );
  274. extern char *sockstate( tcp_Socket *s );
  275. extern getpeername( tcp_Socket *s, void *dest, int *len );
  276. extern getsockname(  tcp_Socket *s, void *dest, int *len );
  277. extern longword gethostid();
  278. extern longword sethostid( longword ip );
  279. extern char *getdomainname( char *name, int length );
  280. extern char *setdomainname( char *string );
  281. extern char *gethostname( char *name, int length );
  282. extern char *sethostname( char *string );
  283. extern word ntohs( word a );
  284. extern word htons( word a );
  285. extern longword ntohl( longword x );
  286. extern longword htonl( longword x );
  287.  
  288. extern void _arp_register( longword use, longword instead_of );
  289. extern int _arp_resolve( longword ina, void *ethap, int nowait );
  290.  
  291. extern _survivebootp;
  292. extern int sock_established( tcp_Socket *s);
  293. extern sock_stats( tcp_Socket *s, word *days, word *inactive, word *cwindow, word *avg, word *sd );
  294. extern int addwattcpd( void (*p)() );
  295. extern int delwattcpd( void (*p)() );
  296. extern int tap_add( void *socket, void *userid );
  297. #endif /* WTCP_VER */
  298.  
  299. #endif /* ndef _wattcp_tcp_h */
  300.